package Future;

import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class OverTimesDemo {
	public static void main(String[] args) {
		ExecutorService exec = Executors.newSingleThreadExecutor();
		CallableDemos sendMail = new CallableDemos("sendmail");
		Future<String> future = exec.submit(sendMail);
		exec.shutdown();// 调用 shutdown 拒绝传入任务，然后调用 shutdownNow（如有必要）取消所有遗留的任务： 
		try {
			String obj = future.get(100 * 1, TimeUnit.MILLISECONDS);
			System.out.println("开始处理" + obj);
		} catch (TimeoutException e) {
			System.out.println("处理超时");
			exec.shutdownNow();
		} catch (Exception e) {
			System.out.println("处理失败");
			exec.shutdownNow();
		}
		System.out.println("线程完毕");
	}
}
